﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ecdl.demo.model.expression {
    public class ExpressionContext {
        private static readonly ExpressionContext EMPTY = new ExpressionContext();

        public ExpressionContext() {
        }

        public ExpressionContext(Object context) {
            Context = context;
        }

        public Object Context { get; private set; }

        public bool HasContext<ContextType>() {
            Object context = Context;
            return context != null && typeof(ContextType).IsAssignableFrom(context.GetType());
        }

        public ContextType GetContext<ContextType>() {
            return (ContextType)Context;
        }

        public IEnumerable<ContextType> ContextAsList<ContextType>(){
            List<ContextType> list = new List<ContextType>();
            list.Add(GetContext<ContextType>());
            return list;
        }

        public static ExpressionContext Empty {
            get {
                return ExpressionContext.EMPTY;
            }
        }
    }
}
